<?php
if (!defined('ENGINE_NAME')) die ("You can't access this file directly!");

class CTimer
{
	var $aEvents = array();

	/**
	* Start timer
	* @author NG CMS Team, Bogdan Tkachenko (http://bogus.mail.ua)
	* @return true
	*/
	function Start()
	{
		list($iUSec, $iSec) = explode(' ', microtime());
		$this->iScriptStart = (float) $iSec + (float) $iUSec;
		return true;
	}

	/**
	* Stop timer
	* @author NG CMS Team, Bogdan Tkachenko (http://bogus.mail.ua)
	* @param iPoints Round output time by this number
	* @return time from Start() call
	*/
	function Stop($iPoints = 2)
	{
		list($iUSec, $iSec) = explode(' ', microtime());
		$iScriptEnd = (float) $iSec + (float) $iUSec;
		$iElapsedTime = round($iScriptEnd - $this->iScriptStart, $iPoints);

		return $iElapsedTime;
	}

	/**
	* Clear all events
	* @author NG CMS Team, Bogdan Tkachenko (http://bogus.mail.ua)
	* @return true
	*/
	function ClearEvents()
	{
		$this->aEvents = array();
		return true;
	}

	/**
	* Register new event
	* @author NG CMS Team, Bogdan Tkachenko (http://bogus.mail.ua)
	* @param sEventName Event name
	* @param sEventParams Event params
	* @return true
	*/
	function RegisterEvent($sEventText, $sEventParams = '')
	{
		array_push($this->aEvents, array(
			'time'	=> $this->Stop(4),
			'text'	=> $sEventText,
			'params'=> $sEventParams)
		);
		return true;
	}
}
